package com.wenwu.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenwu.common.bean.RelicsPreserve;
import com.wenwu.common.exception.RelicsException;
import com.wenwu.common.page.PaginationVO;
import com.wenwu.dao.RelicsBasicMapper;
import com.wenwu.dao.RelicsPreserveMapper;
import com.wenwu.service.ProtectSatuationService;
/**
	 * 添加方法
	 */
/**
	 * 查询多少条
	 */
/**
	 * 查询集合
	 */
/**
	 * 按照主键查询
	 */
/**
	 * 按照basicId主键查询
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 添加方法
	 */
/**
	 * 查询多少条
	 */
/**
	 * 查询集合
	 */
/**
	 * 按照主键查询
	 */
/**
	 * 按照basicId主键查询
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 添加方法
	 */
/**
	 * 查询多少条
	 */
/**
	 * 查询集合
	 */
/**
	 * 按照主键查询
	 */
/**
	 * 按照basicId主键查询
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 添加方法
	 */
/**
	 * 查询多少条
	 */
/**
	 * 查询集合
	 */
/**
	 * 按照主键查询
	 */
/**
	 * 按照basicId主键查询
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 添加方法
	 */
/**
	 * 查询多少条
	 */
/**
	 * 查询集合
	 */
/**
	 * 按照主键查询
	 */
/**
	 * 按照basicId主键查询
	 */
/**
	 * 按照主键集合删除
	 */
/**
	 * 按照主键集合删除
	 */
@Service
public class ProtectSatuationServiceImpl implements ProtectSatuationService {

	@Autowired
	private RelicsPreserveMapper relicsPreserveMapper;
	@Autowired
	private RelicsBasicMapper basicMapper;
	Logger log = Logger.getLogger(this.getClass());

	/**
	 * 添加方法
	 */
	public String addObj(RelicsPreserve relicsPreserve) throws RelicsException {
		try {
			int upRecordNum = 0;
			if (relicsPreserve.getPreserveId() == null) {
				upRecordNum = relicsPreserveMapper
						.insertSelective(relicsPreserve);
				if (upRecordNum > 0) {
					return "保存现状添加成功";
				} else {
					return "保存现状添加失败";
				}
			} else {
				upRecordNum = relicsPreserveMapper
						.updateByPrimaryKeySelective(relicsPreserve);
				if (upRecordNum > 0) {
					return "保存现状修改成功";
				} else {
					return "保存现状修改失败";
				}
			}
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	/**
	 * 查询多少条
	 */
	public int selectTotalRecord(RelicsPreserve relicsPreserve)
			throws RelicsException {
		return relicsPreserveMapper.selectTotalRecord(relicsPreserve);
	}

	/**
	 * 查询集合
	 */
	public PaginationVO selectList(RelicsPreserve relicsPreserve,
			PaginationVO pageVo) throws RelicsException {
	
			try {
				pageVo.setTotalRecord(relicsPreserveMapper.selectTotalRecord(relicsPreserve));
				System.out.println(relicsPreserveMapper.selectList(relicsPreserve, pageVo).size());
				pageVo.setList(relicsPreserveMapper.selectList(relicsPreserve, pageVo));
			} catch (Exception e) {
				throw new RelicsException("系统异常");
			}
			return pageVo;
	}

	/**
	 * 按照主键查询
	 */
	public RelicsPreserve selectRelicsPreserveByPreserveId(Integer preserveId)
			throws RelicsException {
		return relicsPreserveMapper.selectByPrimaryKey(preserveId);
	}

	/**
	 * 按照basicId主键查询
	 */
	public RelicsPreserve selectRelicsPreserveByBasicId(Integer basicId)
			throws RelicsException {
		try {
			return relicsPreserveMapper.selectRelicsPreserveByBasicId(basicId);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	/**
	 * 按照主键集合删除
	 */
	public int deleteByKey(List<?> keys) throws RelicsException {

		try {
			return relicsPreserveMapper.deleteByKey(keys);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

}
